﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;

namespace OracleDAL.Room
{
   /// <summary>
	/// 数据访问类ROOM_EQUIPMENTSUPSUB。
	/// </summary>
	public class ROOM_EQUIPMENTSUPSUB
	{
		public ROOM_EQUIPMENTSUPSUB()
		{}
		#region  成员方法

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string LOGICEQUIPMENTID,string UPLOGICEQUMENTID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from ROOM_EQUIPMENTSUPSUB");
			strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID and UPLOGICEQUMENTID=:UPLOGICEQUMENTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,50),
					new OracleParameter(":UPLOGICEQUMENTID", OracleType.VarChar,50)};
			parameters[0].Value = LOGICEQUIPMENTID;
			parameters[1].Value = UPLOGICEQUMENTID;

			return OracleHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Model.Room.ROOM_EQUIPMENTSUPSUB model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ROOM_EQUIPMENTSUPSUB(");
			strSql.Append("LOGICEQUIPMENTID,UPLOGICEQUMENTID,EQUIPTYPE,CREATETIME,CREATEUSERISN,MODIFYTIME,MODIFYUSERISN,EQUIPMENTID,EQUIPMENT_PERF,ISMONITORALARM,ISMONITORPERF,ORDERINDEX)");
			strSql.Append(" values (");
			strSql.Append(":LOGICEQUIPMENTID,:UPLOGICEQUMENTID,:EQUIPTYPE,:CREATETIME,:CREATEUSERISN,:MODIFYTIME,:MODIFYUSERISN,:EQUIPMENTID,:EQUIPMENT_PERF,:ISMONITORALARM,:ISMONITORPERF,:ORDERINDEX)");
			OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,25),
					new OracleParameter(":UPLOGICEQUMENTID", OracleType.VarChar,25),
					new OracleParameter(":EQUIPTYPE", OracleType.VarChar,25),
					new OracleParameter(":CREATETIME", OracleType.DateTime),
					new OracleParameter(":CREATEUSERISN", OracleType.VarChar,25),
					new OracleParameter(":MODIFYTIME", OracleType.DateTime),
					new OracleParameter(":MODIFYUSERISN", OracleType.VarChar,25),
					new OracleParameter(":EQUIPMENTID", OracleType.VarChar,25),
					new OracleParameter(":EQUIPMENT_PERF", OracleType.VarChar,1000),
					new OracleParameter(":ISMONITORALARM", OracleType.VarChar,5),
					new OracleParameter(":ISMONITORPERF", OracleType.VarChar,5),
					new OracleParameter(":ORDERINDEX", OracleType.Number,4)};
			parameters[0].Value = model.LOGICEQUIPMENTID;
			parameters[1].Value = model.UPLOGICEQUMENTID;
			parameters[2].Value = model.EQUIPTYPE;
			parameters[3].Value = model.CREATETIME;
			parameters[4].Value = model.CREATEUSERISN;
			parameters[5].Value = model.MODIFYTIME;
			parameters[6].Value = model.MODIFYUSERISN;
			parameters[7].Value = model.EQUIPMENTID;
			parameters[8].Value = model.EQUIPMENT_PERF;
			parameters[9].Value = model.ISMONITORALARM;
			parameters[10].Value = model.ISMONITORPERF;
			parameters[11].Value = model.ORDERINDEX;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(Model.Room.ROOM_EQUIPMENTSUPSUB model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ROOM_EQUIPMENTSUPSUB set ");
			strSql.Append("EQUIPTYPE=:EQUIPTYPE,");
			strSql.Append("CREATETIME=:CREATETIME,");
			strSql.Append("CREATEUSERISN=:CREATEUSERISN,");
			strSql.Append("MODIFYTIME=:MODIFYTIME,");
			strSql.Append("MODIFYUSERISN=:MODIFYUSERISN,");
			strSql.Append("EQUIPMENTID=:EQUIPMENTID,");
			strSql.Append("EQUIPMENT_PERF=:EQUIPMENT_PERF,");
			strSql.Append("ISMONITORALARM=:ISMONITORALARM,");
			strSql.Append("ISMONITORPERF=:ISMONITORPERF,");
			strSql.Append("ORDERINDEX=:ORDERINDEX");
			strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID and UPLOGICEQUMENTID=:UPLOGICEQUMENTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,25),
					new OracleParameter(":UPLOGICEQUMENTID", OracleType.VarChar,25),
					new OracleParameter(":EQUIPTYPE", OracleType.VarChar,25),
					new OracleParameter(":CREATETIME", OracleType.DateTime),
					new OracleParameter(":CREATEUSERISN", OracleType.VarChar,25),
					new OracleParameter(":MODIFYTIME", OracleType.DateTime),
					new OracleParameter(":MODIFYUSERISN", OracleType.VarChar,25),
					new OracleParameter(":EQUIPMENTID", OracleType.VarChar,25),
					new OracleParameter(":EQUIPMENT_PERF", OracleType.VarChar,1000),
					new OracleParameter(":ISMONITORALARM", OracleType.VarChar,5),
					new OracleParameter(":ISMONITORPERF", OracleType.VarChar,5),
					new OracleParameter(":ORDERINDEX", OracleType.Number,4)};
			parameters[0].Value = model.LOGICEQUIPMENTID;
			parameters[1].Value = model.UPLOGICEQUMENTID;
			parameters[2].Value = model.EQUIPTYPE;
			parameters[3].Value = model.CREATETIME;
			parameters[4].Value = model.CREATEUSERISN;
			parameters[5].Value = model.MODIFYTIME;
			parameters[6].Value = model.MODIFYUSERISN;
			parameters[7].Value = model.EQUIPMENTID;
			parameters[8].Value = model.EQUIPMENT_PERF;
			parameters[9].Value = model.ISMONITORALARM;
			parameters[10].Value = model.ISMONITORPERF;
			parameters[11].Value = model.ORDERINDEX;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string LOGICEQUIPMENTID,string UPLOGICEQUMENTID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ROOM_EQUIPMENTSUPSUB ");
			strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID and UPLOGICEQUMENTID=:UPLOGICEQUMENTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,50),
					new OracleParameter(":UPLOGICEQUMENTID", OracleType.VarChar,50)};
			parameters[0].Value = LOGICEQUIPMENTID;
			parameters[1].Value = UPLOGICEQUMENTID;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
      /// <summary>
        /// 删除一个逻辑设备
      /// </summary>
      /// <param name="LOGICEQUIPMENTID">逻辑设备ID</param>
        public void DeleteLogicEquip(string LOGICEQUIPMENTID)
        {
            ArrayList al = new ArrayList();
            al.Add("delete from ROOM_EQUIPMENTSUPSUB  where LOGICEQUIPMENTID='" + LOGICEQUIPMENTID + "'");
            al.Add("delete from ROOM_EQUIPMENTLAYOUT  where LOGICEQUIPMENTID='" + LOGICEQUIPMENTID + "'");
            OracleHelper.ExecuteSqlTran(al);
        }

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.Room.ROOM_EQUIPMENTSUPSUB GetModel(string LOGICEQUIPMENTID,string UPLOGICEQUMENTID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select LOGICEQUIPMENTID,UPLOGICEQUMENTID,EQUIPTYPE,CREATETIME,CREATEUSERISN,MODIFYTIME,MODIFYUSERISN,EQUIPMENTID,EQUIPMENT_PERF,ISMONITORALARM,ISMONITORPERF,ORDERINDEX from ROOM_EQUIPMENTSUPSUB ");
			strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID and UPLOGICEQUMENTID=:UPLOGICEQUMENTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,50),
					new OracleParameter(":UPLOGICEQUMENTID", OracleType.VarChar,50)};
			parameters[0].Value = LOGICEQUIPMENTID;
			parameters[1].Value = UPLOGICEQUMENTID;

			Model.Room.ROOM_EQUIPMENTSUPSUB model=new Model.Room.ROOM_EQUIPMENTSUPSUB();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.LOGICEQUIPMENTID=ds.Tables[0].Rows[0]["LOGICEQUIPMENTID"].ToString();
				model.UPLOGICEQUMENTID=ds.Tables[0].Rows[0]["UPLOGICEQUMENTID"].ToString();
				model.EQUIPTYPE=ds.Tables[0].Rows[0]["EQUIPTYPE"].ToString();
				if(ds.Tables[0].Rows[0]["CREATETIME"].ToString()!="")
				{
					model.CREATETIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATETIME"].ToString());
				}
				model.CREATEUSERISN=ds.Tables[0].Rows[0]["CREATEUSERISN"].ToString();
				if(ds.Tables[0].Rows[0]["MODIFYTIME"].ToString()!="")
				{
					model.MODIFYTIME=DateTime.Parse(ds.Tables[0].Rows[0]["MODIFYTIME"].ToString());
				}
				model.MODIFYUSERISN=ds.Tables[0].Rows[0]["MODIFYUSERISN"].ToString();
				model.EQUIPMENTID=ds.Tables[0].Rows[0]["EQUIPMENTID"].ToString();
				model.EQUIPMENT_PERF=ds.Tables[0].Rows[0]["EQUIPMENT_PERF"].ToString();
				model.ISMONITORALARM=ds.Tables[0].Rows[0]["ISMONITORALARM"].ToString();
				model.ISMONITORPERF=ds.Tables[0].Rows[0]["ISMONITORPERF"].ToString();
				if(ds.Tables[0].Rows[0]["ORDERINDEX"].ToString()!="")
				{
					model.ORDERINDEX=int.Parse(ds.Tables[0].Rows[0]["ORDERINDEX"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Room.ROOM_EQUIPMENTSUPSUB GetModel(string LOGICEQUIPMENTID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select LOGICEQUIPMENTID,UPLOGICEQUMENTID,EQUIPTYPE,CREATETIME,CREATEUSERISN,MODIFYTIME,MODIFYUSERISN,EQUIPMENTID,EQUIPMENT_PERF,ISMONITORALARM,ISMONITORPERF,ORDERINDEX from ROOM_EQUIPMENTSUPSUB ");
            strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID ");
            OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,50)};
            parameters[0].Value = LOGICEQUIPMENTID;

            Model.Room.ROOM_EQUIPMENTSUPSUB model = new Model.Room.ROOM_EQUIPMENTSUPSUB();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.LOGICEQUIPMENTID = ds.Tables[0].Rows[0]["LOGICEQUIPMENTID"].ToString();
                model.UPLOGICEQUMENTID = ds.Tables[0].Rows[0]["UPLOGICEQUMENTID"].ToString();
                model.EQUIPTYPE = ds.Tables[0].Rows[0]["EQUIPTYPE"].ToString();
                if (ds.Tables[0].Rows[0]["CREATETIME"].ToString() != "")
                {
                    model.CREATETIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATETIME"].ToString());
                }
                model.CREATEUSERISN = ds.Tables[0].Rows[0]["CREATEUSERISN"].ToString();
                if (ds.Tables[0].Rows[0]["MODIFYTIME"].ToString() != "")
                {
                    model.MODIFYTIME = DateTime.Parse(ds.Tables[0].Rows[0]["MODIFYTIME"].ToString());
                }
                model.MODIFYUSERISN = ds.Tables[0].Rows[0]["MODIFYUSERISN"].ToString();
                model.EQUIPMENTID = ds.Tables[0].Rows[0]["EQUIPMENTID"].ToString();
                model.EQUIPMENT_PERF = ds.Tables[0].Rows[0]["EQUIPMENT_PERF"].ToString();
                model.ISMONITORALARM = ds.Tables[0].Rows[0]["ISMONITORALARM"].ToString();
                model.ISMONITORPERF = ds.Tables[0].Rows[0]["ISMONITORPERF"].ToString();
                if (ds.Tables[0].Rows[0]["ORDERINDEX"].ToString() != "")
                {
                    model.ORDERINDEX = int.Parse(ds.Tables[0].Rows[0]["ORDERINDEX"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select LOGICEQUIPMENTID,UPLOGICEQUMENTID,EQUIPTYPE,CREATETIME,CREATEUSERISN,MODIFYTIME,MODIFYUSERISN,EQUIPMENTID,EQUIPMENT_PERF,ISMONITORALARM,ISMONITORPERF,ORDERINDEX ");
			strSql.Append(" FROM ROOM_EQUIPMENTSUPSUB ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return OracleHelper.Query(strSql.ToString());
		}
        /// <summary>
        /// 获得数据列表,将设备的基本逻辑属性获取
        /// </summary>
        public DataSet GetListCom(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RE.LOGICEQUIPMENTID,RE.UPLOGICEQUMENTID,RE.EQUIPTYPE,RE.EQUIPMENTID,RE.EQUIPMENT_PERF,RE.ISMONITORALARM,RE.ISMONITORPERF,RE.ORDERINDEX,");
            strSql.Append("REL.LOGICEQUIPMENTNAME,REL.LEFT,REL.EQUIPMENTPROPERTY,REL.TOP,REL.TYPE,REL.REMARK  ");
            strSql.Append(" from ROOM_EQUIPMENTSUPSUB RE,ROOM_EQUIPMENTLAYOUT REL ");
            strSql.Append(" where RE.LOGICEQUIPMENTID = REL.LOGICEQUIPMENTID");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere);
            }
            strSql.Append("  order by RE.ORDERINDEX ");
            return OracleHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表,将设备的基本逻辑属性获取
        /// </summary>
        public DataSet GetListCom(string strWhere,string TABLENAME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RE.LOGICEQUIPMENTID,RE.UPLOGICEQUMENTID,RE.EQUIPTYPE,RE.EQUIPMENTID,RE.EQUIPMENT_PERF,RE.ISMONITORALARM,RE.ISMONITORPERF,RE.ORDERINDEX,");
            strSql.Append("REL.LOGICEQUIPMENTNAME,REL.LEFT,REL.EQUIPMENTPROPERTY,REL.TOP,REL.TYPE ");
            strSql.Append(" from ");
            strSql.Append(TABLENAME + " RE,ROOM_EQUIPMENTLAYOUT REL ");
            strSql.Append(" where RE.LOGICEQUIPMENTID = REL.LOGICEQUIPMENTID");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere);
            }
            strSql.Append("  order by RE.ORDERINDEX ");
            return OracleHelper.Query(strSql.ToString());
        }
		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "ROOM_EQUIPMENTSUPSUB";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
	}
}

